/* 
 * format - haXe File Formats
 *
 *  FV4 File Format
 *  Jan Flanders
 */
 
package format.f4v;
import haxe.Int32;
import format.f4v.Data;
import format.f4v.Constants;

class Writer 
{
	var output : haxe.io.Output;
	var o : haxe.io.BytesOutput;
	var compressed : Bool;
	//var bits : format.tools.BitsOutput;

	public function new(o) 
	{
		this.output = o;
		o.bigEndian=true;
	}

	public function write( v : F4V ) 
	{
		for( b in v.boxes )
			writeBox(b);
	}
	public function writeHeader(h)
	{
		o.writeUInt30(h.size);
		o.writeString(h.type);
	}
	public function writeBox( b : Box )
	{
		switch( b ) 
		{
			case Ftyp(header, ftypData):
				writeHeader(header);
				o.writeInt32(ftypData.majorBrand);
				o.writeUInt32(ftypData.minorVersion);
				for(i in ftypData.compatibleBrands)
					o.writeInt32(i);
			case Unknown(header, data):
				writeHeader(header);
				o.write(data);
		}
	}
}
